<?php

class CmpReportController extends BaseController
{

	/**
	 * Displays a particular model.
	 * @param integer $id the ID of the model to be displayed
	 */
	public function actionView()
	{
		$id = isset($_GET['id'])?$_GET['id']:$_POST['Refund']['zr_id'];
		$model = MemReport::model()->findByPk($id);

		$this->render('view',array(
			'model'=>$model
		));

	}


	/**
	 * Manages all models.
	 */
	public function actionAdmin()
	{
		$model=new MemReport('search');
		$model->unsetAttributes();  // clear any default values

		//1维权2举报
		$model->zmr_type=2;
		
		if(isset($_GET['MemReport'])){
			$model->attributes=$_GET['MemReport'];
		}

		$this->render('admin',array(
			'model'=>$model,
		));
	}

	/**
	 * Returns the data model based on the primary key given in the GET variable.
	 * If the data model is not found, an HTTP exception will be raised.
	 * @param integer the ID of the model to be loaded
	 */
	public function loadModel($id)
	{
		$model=MemReport::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}

	/**
	 * Performs the AJAX validation.
	 * @param CModel the model to be validated
	 */
	protected function performAjaxValidation($model)
	{
		if(isset($_POST['ajax']) && $_POST['ajax']==='mem-report-form')
		{
			echo CActiveForm::validate($model);
			Yii::app()->end();
		}
	}
	
	/**
	 * 单条，批量删除
	 */
	public function actionDelete(){
		//操作ID号格式处理
		if(isset($_GET['id'])){
			$id = $_GET['id'];
		}elseif(isset($_POST['ids'])){
			$id =$_POST['ids'];
		}else{
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
		}
		$id = is_array($id)?join(',',$id):(int)$id;
		//处理条件
		$criteria=new CDbCriteria;
		$criteria->addCondition("zmr_id in ($id)");
		//修改内容
		$set = array('zmr_del'=>'2');//逻辑删除
		//执行操作
		if(MemReport::model()->updateAll($set,$criteria)){
			//成功跳转
			$this->redirect(Yii::app()->request->urlReferrer);
		}
	}
	
	
}
